# create_sample_audio.py
import os
import numpy as np
from scipy.io import wavfile

def create_sample_audio_files():
    """创建示例音频文件"""
    audio_dir = "assets/audio"
    os.makedirs(audio_dir, exist_ok=True)
    
    print("🎵 创建示例音频文件...")
    
    # 1. 创建简单的背景音乐（正弦波）
    def create_background_music(filename, duration=30, freq=440):
        sample_rate = 44100
        t = np.linspace(0, duration, int(sample_rate * duration))
        
        # 创建和弦
        wave1 = 0.3 * np.sin(2 * np.pi * freq * t)
        wave2 = 0.2 * np.sin(2 * np.pi * freq * 1.5 * t)
        wave3 = 0.1 * np.sin(2 * np.pi * freq * 2 * t)
        
        # 合并波形
        audio_data = wave1 + wave2 + wave3
        
        # 转换为立体声
        stereo_data = np.column_stack([audio_data, audio_data])
        
        # 保存为WAV文件
        wavfile.write(filename, sample_rate, (stereo_data * 32767).astype(np.int16))
        print(f"✅ 创建: {filename}")
    
    # 2. 创建转场音效
    def create_transition_sound(filename, duration=1.0, freq=800):
        sample_rate = 44100
        t = np.linspace(0, duration, int(sample_rate * duration))
        
        # 创建衰减的正弦波
        envelope = np.exp(-3 * t)  # 衰减包络
        audio_data = envelope * np.sin(2 * np.pi * freq * t)
        
        # 转换为立体声
        stereo_data = np.column_stack([audio_data, audio_data])
        
        # 保存为WAV文件
        wavfile.write(filename, sample_rate, (stereo_data * 32767).astype(np.int16))
        print(f"✅ 创建: {filename}")
    
    # 创建背景音乐
    create_background_music(f"{audio_dir}/background_1.mp3", 30, 440)
    create_background_music(f"{audio_dir}/background_2.mp3", 30, 330)
    create_background_music(f"{audio_dir}/background_3.mp3", 30, 550)
    
    # 创建转场音效
    create_transition_sound(f"{audio_dir}/transition_1.wav", 1.0, 800)
    create_transition_sound(f"{audio_dir}/transition_2.wav", 1.0, 1200)
    
    print("🎉 示例音频文件创建完成！")
    print("💡 提示: 您可以用自己的音频文件替换这些示例文件")

if __name__ == "__main__":
    create_sample_audio_files()